package com.yonyou.pmclouds.workflow.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.iuap.tenant.sdk.TenantCenter;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.util.YhtSdkProperties;
import com.yonyou.pmclouds.workflow.entity.ProcessDataSynVO;
import com.yonyou.pmclouds.workflow.service.rmiitf.BaseManagerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/baseManager")
public class BaseManagerController{

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private BaseManagerService baseManagerService;

    /**
     * 云审批基础数据同步
     * @param userId 操作人
     * @param tenantId 当前租户
     * @return 同步结果
     */
    @RequestMapping("/dataSyn")
    public String addDataSyn(@RequestParam("userId") String userId, @RequestParam("tenantId") String tenantId)
            throws BusinessException{

        // 同步租户信息到云审批
        String tenantInfo = TenantCenter.getTenantById(tenantId);
        String sysId = StringUtils.isEmpty(YhtSdkProperties.getSysId()) ?
                ApplicationConsts.APPLICATION_ID : YhtSdkProperties.getSysId();

        return baseManagerService.addDataSyn(tenantInfo, userId, tenantId, sysId);
    }

    @RequestMapping("/queryLastSynInfo")
    public ProcessDataSynVO queryLastSynInfo(@RequestParam("tenantId") String tenantId) throws BusinessException{
        return baseManagerService.queryLastSynInfo(tenantId);
    }

}
